/*
 * Service Definition: http://services.faa.gov/docs/services/airport/
 * Example Usage: http://services.faa.gov/airport/status/PKB?format=application/json
 */

var tgd = tgd || {};
tgd.Services = tgd.Services || {};
tgd.Services.FAA = tgd.Services.FAA || {};

tgd.Services.FAA.AirportStatus = function (airportCode, callback) {
	this._code = airportCode;
	this._callback = callback;
	this._data = null;

	if (tgd.Services.FAA.AirportStatus._initialized === undefined) {

		tgd.Services.FAA.AirportStatus.prototype._TODO = function() {
			if (this._request.readyState == 4) {
				this._data = eval('(' + this._request.responseText + ')');
				this._callback();
			}
		}

		tgd.Services.FAA.AirportStatus.prototype.refresh = function() {
			this._request.open("GET", "http://services.faa.gov/airport/status/" + this._code + "?format=application/json", true);
			this._request.send(null);
		}

		tgd.Services.FAA.AirportStatus.prototype.getData = function() {
			return this._data;
		}

		tgd.Services.FAA.AirportStatus._initialized = true;
	}

	var self = this;
	this._request = new XMLHttpRequest();
	this._request.onreadystatechange = function() {
		if (self._request.readyState == 4) {
			self._data = eval('(' + self._request.responseText + ')');
			self._callback();
		}
	};

	this.refresh();
}
